<template>
  <div class="login-container">
    <div class="login-box">
      <!-- Left side - Login Form -->
      <div class="login-form-container">
        <h1 class="title">登陆</h1>
        <p class="subtitle">欢迎来到MyPostman，请输入账号密码！</p>

        <form @submit.prevent="handleLogin" class="login-form">
          <div class="form-group">
            <input
                type="text"
                v-model="loginForm.username"
                placeholder="用户名"
                class="input"
            />
          </div>

          <div class="form-group">
            <input
                type="password"
                v-model="loginForm.password"
                placeholder="密码"
                class="input"
            />
          </div>

          <div class="remember-me">
            <input
                type="checkbox"
                v-model="loginForm.remember"
                id="remember"
            />
            <label for="remember">记住我</label>
          </div>

          <button type="submit" class="submit-btn">
            登陆
          </button>

          <div class="forgot-password">
            <a href="#">忘记密码，点我重置！</a>
          </div>
        </form>

        <div class="third-party">
          <p>第三方账号登入</p>
          <div class="social-buttons">
            <button class="social-btn green"></button>
            <button class="social-btn blue"></button>
            <button class="social-btn black"></button>
          </div>
        </div>
      </div>

      <!-- Right side - Image -->
      <div class="welcome-container">
        <div class="welcome-content">
          <h2>Mypostman欢迎您登陆！</h2>
          <p>如果你没有账号，你想要现在注册一个吗？</p>
          <button @click="showRegisterModal = true" class="register-btn">
            注册
          </button>
        </div>
      </div>
    </div>

    <!-- Registration Modal -->
    <div v-if="showRegisterModal" class="modal-overlay">
      <div class="modal">
        <div class="modal-header">
          <h2>注册新账号</h2>
          <button @click="showRegisterModal = false" class="close-btn">✕</button>
        </div>

        <form @submit.prevent="handleRegister" class="register-form">
          <div class="form-group">
            <input
                type="text"
                v-model="registerForm.username"
                placeholder="用户名"
                class="input"
            />
          </div>

          <div class="form-group">
            <input
                type="email"
                v-model="registerForm.email"
                placeholder="电子邮箱"
                class="input"
            />
          </div>

          <div class="form-group">
            <input
                type="password"
                v-model="registerForm.password"
                placeholder="密码"
                class="input"
            />
          </div>

          <div class="form-group">
            <input
                type="password"
                v-model="registerForm.confirmPassword"
                placeholder="确认密码"
                class="input"
            />
          </div>

          <button type="submit" class="submit-btn" @onclick="closeRegisterModal">
            注册
          </button>
        </form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showRegisterModal: false,
      loginForm: {
        username: '',
        password: '',
        remember: false
      },
      registerForm: {
        username: '',
        email: '',
        password: '',
        confirmPassword: ''
      }
    }
  },
  methods: {
    handleLogin() {
      this.$router.push('/welcome');
    },
    handleRegister() {
      console.log('Register form submitted:', this.registerForm);
      // 关闭模态框
      this.closeRegisterModal();
    },
    closeRegisterModal() {
      this.showRegisterModal = false;
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background-color: #f3f4f6;
}

.login-box {
  background-color: white;
  border-radius: 1rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  width: 100%;
  max-width: 1200px;
  display: flex;
}

.login-form-container {
  width: 50%;
  padding: 2.5rem;
}

.title {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: #666;
  margin-bottom: 2rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  width: 100%;
}

.input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 9999px;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus {
  border-color: #6b7280;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.submit-btn {
  width: 100%;
  padding: 0.75rem;
  background-color: black;
  color: white;
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.submit-btn:hover {
  background-color: #1f2937;
}

.forgot-password {
  text-align: center;
}

.forgot-password a {
  color: #666;
  text-decoration: none;
}

.forgot-password a:hover {
  color: #1f2937;
}

.third-party {
  margin-top: 2rem;
}

.third-party p {
  color: #666;
  margin-bottom: 1rem;
}

.social-buttons {
  display: flex;
  gap: 1rem;
}

.social-btn {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 0.2s;
}

.social-btn:hover {
  opacity: 0.8;
}

.social-btn.green {
  background-color: #10b981;
}

.social-btn.blue {
  background-color: #3b82f6;
}

.social-btn.black {
  background-color: #000;
}

.welcome-container {
  width: 50%;
  background-color: #f9fafb;
  padding: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-content {
  text-align: center;
}

.welcome-content h2 {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.welcome-content p {
  color: #666;
  margin-bottom: 2rem;
}

.register-btn {
  padding: 0.75rem 2rem;
  border: 2px solid #1f2937;
  border-radius: 9999px;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.register-btn:hover {
  background-color: #1f2937;
  color: white;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background-color: white;
  border-radius: 1rem;
  padding: 2rem;
  width: 100%;
  max-width: 500px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: bold;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #666;
  cursor: pointer;
  transition: color 0.2s;
}

.close-btn:hover {
  color: #1f2937;
}

.register-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .login-box {
    flex-direction: column;
  }

  .login-form-container,
  .welcome-container {
    width: 100%;
  }

  .welcome-container {
    padding: 2rem;
  }
}
</style>